package beer.xz.beer.device.comm//package com.example.beer
//
//import beer.xz.beer.device.comm.serial.BeerSerialHandler
//import java.util.Scanner
//
///**
// * 啤酒机通信测试应用
// */
//fun main(args: Array<String>) {
//    println("Beer Machine Communication Test")
//
//    // 从参数获取端口名称或使用默认值
//    val portName = args.firstOrNull() ?: "/dev/ttyUSB0"
//
//    println("Using protocol with:")
//    println("- Baud rate: 115200")
//    println("- Data bits: 8")
//    println("- Parity: None")
//    println("- Stop bits: 1")
//    println("- Fixed data length: 180 bytes")
//    println("- Header: 0x0F")
//    println("- Tail: 0x0D 0x0A")
//
//    // 创建串口处理器
//    val serialHandler = BeerSerialHandler(portName)
//
//    // 打开串口
//    if (!serialHandler.open()) {
//        println("Failed to open serial port: $portName")
//        return
//    }
//
//    println("Connected to port: $portName")
//
//    // Interactive command loop
//    val scanner = Scanner(System.`in`)
//
//    while (true) {
//        println("\nAvailable commands:")
//        println("1. Query Status")
//        println("2. Set Temperature")
//        println("3. Start Brewing")
//        println("4. Stop Brewing")
//        println("5. Start Cleaning")
//        println("6. Stop Cleaning")
//        println("7. Reset System")
//        println("8. Calibrate Weight")
//        println("9. Set Flow Rate")
//        println("10. Set Motor Position")
//        println("0. Exit")
//
//        print("Enter command: ")
//        val choice = scanner.nextLine().trim()
//
//        when (choice) {
//            "0" -> break
//            "1" -> {
//                // Query status
//                val commandData = CommandBuilder.queryStatus()
//                serialHandler.sendCommandData(commandData)
//                println("Sent query status command")
//            }
//            "2" -> {
//                // Set temperature
//                print("Enter temperature (0-100°C): ")
//                val temp = scanner.nextLine().toIntOrNull() ?: 0
//                val commandData = CommandBuilder.setTemperature(temp)
//                serialHandler.sendCommandData(commandData)
//                println("Sent set temperature command: $temp°C")
//            }
//            "3" -> {
//                // Start brewing
//                val commandData = CommandBuilder.startBrewing()
//                serialHandler.sendCommandData(commandData)
//                println("Sent start brewing command")
//            }
//            "4" -> {
//                // Stop brewing
//                val commandData = CommandBuilder.stopBrewing()
//                serialHandler.sendCommandData(commandData)
//                println("Sent stop brewing command")
//            }
//            "5" -> {
//                // Start cleaning
//                val commandData = CommandBuilder.startCleaning()
//                serialHandler.sendCommandData(commandData)
//                println("Sent start cleaning command")
//            }
//            "6" -> {
//                // Stop cleaning
//                val commandData = CommandBuilder.stopCleaning()
//                serialHandler.sendCommandData(commandData)
//                println("Sent stop cleaning command")
//            }
//            "7" -> {
//                // Reset system
//                val commandData = CommandBuilder.resetSystem()
//                serialHandler.sendCommandData(commandData)
//                println("Sent reset system command")
//            }
//            "8" -> {
//                // Calibrate weight
//                print("Enter sensor index (1-4): ")
//                val sensorIndex = scanner.nextLine().toIntOrNull() ?: 1
//                print("Enter weight value: ")
//                val weight = scanner.nextLine().toFloatOrNull() ?: 0f
//
//                val commandData = CommandBuilder.calibrateWeight(sensorIndex, weight)
//                serialHandler.sendCommandData(commandData)
//                println("Sent calibrate weight command for sensor $sensorIndex with value $weight")
//            }
//            "9" -> {
//                // Set flow rate
//                print("Enter flow rate: ")
//                val flowRate = scanner.nextLine().toFloatOrNull() ?: 0f
//
//                val commandData = CommandBuilder.setFlowRate(flowRate)
//                serialHandler.sendCommandData(commandData)
//                println("Sent set flow rate command: $flowRate")
//            }
//            "10" -> {
//                // Set motor position
//                print("Enter motor position: ")
//                val position = scanner.nextLine().toFloatOrNull() ?: 0f
//
//                val commandData = CommandBuilder.setMotorPosition(position)
//                serialHandler.sendCommandData(commandData)
//                println("Sent set motor position command: $position")
//            }
//            else -> {
//                println("Invalid command")
//            }
//        }
//    }
//
//    // Close the port
//    serialHandler.close()
//    println("Disconnected from port: $portName")
//}
